<?php 

class News {

	public function __construct(){
		$this->query = DB::table('news');
	}

	public function addNews($news_array) {
		$news_array['ctime'] = date('Y-m-j g:i:s');
		$news_array['mtime'] = time();
		return $this->query->insert($news_array);	
	}

	public function updateNews($id,$update_array){
		$update_array['mtime'] = time();
		return $this->query
			->where('id', '=', $id)
			->update($update_array);		
	}

	public function deleteNews($id){
		return $this->query
			->where('id', '=', $id)->delete();
	}

	public function getNews($id){
		return $this->query
			->find($id);
	}

	public function listNews($per_page){
		$ret = $this->query->order_by('ctime', 'desc')
			->paginate($per_page, array('id', 'title', 'content', 'sort_order','type','ctime'));
		return $ret;
	}
}







?>

